# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=v4l-utils
pkgver=1.20.0
pkgrel=0
pkgdesc="Userspace tools and conversion library for Video 4 Linux"
url="http://freshmeat.net/projects/libv4l"
arch="all"
license="LGPL-2.0-or-later"
makedepends="qt5-qtbase-dev libjpeg-turbo-dev argp-standalone linux-headers
	eudev-dev alsa-lib-dev"
subpackages="$pkgname-dev $pkgname-doc qv4l2 $pkgname-dvbv5 $pkgname-libs ir_keytable"
source="https://linuxtv.org/downloads/v4l-utils/v4l-utils-$pkgver.tar.bz2
	getsubopt.patch
	types.patch
	"
build() {
	export CFLAGS="$CFLAGS -D__off_t=off_t"
	export LIBS="-largp -lintl"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--enable-libdvbv5 \
		--disable-static
	make
}

check() {
	make check
}

package() {
	make -j1 DESTDIR="$pkgdir" install
	install -Dm644 "$builddir"/utils/qv4l2/qv4l2.desktop \
		"$pkgdir"/usr/share/applications/qv4l2.desktop
	install -Dm644 "$builddir"/utils/qv4l2/qv4l2.svg \
		"$pkgdir"/usr/share/icons/hicolor/scalable/apps/qv4l2.svg
}

qv4l2() {
	pkgdesc="QT v4l2 test control and streaming test application"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/qv4l2 "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/share "$subpkgdir"/usr/
}

dvbv5() {
	pkgdesc="Backwards compatible DVBv5 command line utilities"
	mkdir -p "$subpkgdir"/usr/bin \
		"$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/bin/dvb* \
		"$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/lib/libdvbv5.* \
		"$subpkgdir"/usr/lib/
}

libs() {
	pkgdesc="Collection of video4linux support libraries"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/* \
		"$subpkgdir"/usr/lib
}

ir_keytable() {
	pkgdesc="Alter keymaps of Remote Controller devices"
	mkdir -p "$subpkgdir"/lib/udev/rc_keymaps \
		"$subpkgdir"/lib/udev/rules.d \
		"$subpkgdir"/usr/bin \
		"$subpkgdir"/etc
	mv "$pkgdir"/lib/udev/rc_keymaps/* \
		"$subpkgdir"/lib/udev/rc_keymaps
	mv "$pkgdir"/lib/udev/rules.d/* \
		"$subpkgdir"/lib/udev/rules.d
	mv "$pkgdir"/usr/bin/ir-keytable \
		"$subpkgdir"/usr/bin
	mv "$pkgdir"/etc/rc_maps.cfg \
		"$subpkgdir"/etc
}

sha512sums="179ca8dbbf7af5fa4870b70f17645d7834fe6ba52670ae6b58473efa257db0cd812ce14f16574cc4491c0bcb218835e4c29f1354882a151687eecec97852fc63  v4l-utils-1.20.0.tar.bz2
3e51af7a77a8f06e1278022362347808b233cf021a277ce9cd66a9553e754bf91b3923c32ab17a86b11f4ef2555a5f1d544d0fc22e82a2997e34060dd561f760  getsubopt.patch
358611fbae8348f17bf49c08820b4641deb1f7282ce2c1e20b8fdf0a85cd73ca4b46f6668c2a7328b5261e401c12f471170a9a1f3fc2982b6897ff11386c06c6  types.patch"
